package com.zyn.es.basic;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.get.GetResponse;

/**
 * 获取数据
 * 
 * @author tongyufu
 *
 */
public class GetAPI extends EsClient {

    Logger log = LogManager.getLogger();

    public static void main(String[] args) {
        GetAPI get = new GetAPI();
        get.get();
    }

    public void get() {
        super.initClient();
        log.info("================================");
        GetResponse response = client.prepareGet(INDEX, TYPE, "20").get();
        log.info("index：" + response.getIndex());
        log.info("type：" + response.getType());
        log.info("id：" + response.getId());
        log.info("version：" + response.getVersion());
        log.info("source：" + response.getSourceAsString());
        log.info("response：" + response);
        client.close();
        log.info("================================");
    }

    public void getByThreaded() {
        super.initClient();
        log.info("================================");
        GetResponse response = client.prepareGet(INDEX, TYPE, "1").setOperationThreaded(true).get();
        log.info("index：" + response.getIndex());
        log.info("type：" + response.getType());
        log.info("id：" + response.getId());
        log.info("version：" + response.getVersion());
        log.info("source：" + response.getSourceAsString());
        log.info("response：" + response);
        client.close();
        log.info("================================");
    }
}
